package mornd.test3;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.DirectFieldAccessor;

import java.util.Date;

/**
 * @author: mornd
 * @dateTime: 2023/5/7 - 22:55
 * 直接通过属性赋值
 */
public class FieldAccessorDemo {
    public static void main(String[] args) {
        User user = new User();
        DirectFieldAccessor accessor = new DirectFieldAccessor(user);
        accessor.setPropertyValue("id", 1001);
        accessor.setPropertyValue("name", "tom");
        accessor.setPropertyValue("birthday", new Date());
        accessor.setPropertyValue("age", 22);
        System.out.println(user);
    }

    @ToString
    static class User {
        private Integer id;
        private String name;
        private Date birthday;
        private int age;
    }
}
